package cn.silver.module.quartz.controller;

import cn.silver.framework.log.annotation.Log;
import cn.silver.framework.log.enums.OperateEnums;
import cn.silver.framework.mybatis.controller.BusController;
import cn.silver.framework.mybatis.controller.DataController;
import cn.silver.framework.openapi.model.Result;
import cn.silver.module.quartz.bean.JobBean;
import cn.silver.module.quartz.domain.SysJob;
import cn.silver.module.quartz.param.JobParam;
import cn.silver.module.quartz.service.ISysJobService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 调度任务信息操作处理
 *
 * @author Silver.Zhou
 */
@RestController
@Tag(name = "调度任务信息操作处理")
@RequestMapping("/monitor/job")
public class SysJobController extends BusController<ISysJobService, SysJob, JobParam, JobBean> {

    @Override
    @Resource
    public void setBaseService(ISysJobService baseService) {
        this.setTitle("调度任务信息操作处理");
        this.setCode("monitor:job");
        this.baseService = baseService;
    }

    /**
     * 定时任务状态修改
     */
    @PutMapping("/changeStatus")
    @Operation(summary = "定时任务状态修改")
    @Log(title = "定时任务", operate = OperateEnums.ALTER_UPDATE)
    public Result<Void> changeStatus(@RequestBody SysJob job) throws SchedulerException {
        baseService.changeStatus(job.getId(), job.getStatus());
        return Result.ok();
    }
    /**
     * 定时任务立即执行一次
     */
    @PutMapping("/run")
    @Operation(summary = "定时任务立即执行一次")
    @Log(title = "定时任务", operate = OperateEnums.ALTER_UPDATE)
    public Result<Void> run(@RequestBody SysJob job) throws SchedulerException {
        baseService.run(job);
        return Result.ok();
    }
}
